JavaScript Global Functions

A visual guide to some of the most common built-in functions.

eval()

Executes a string of JavaScript code. It's powerful but can be dangerous due to security risks, so it should be used with caution. Think of it as a magical box that runs whatever code you feed into it.

eval('10 + 20'); // 30
10 + 20
Result: ?

isFinite()

Determines whether a number is a finite, valid number. It returns true if the number is not `Infinity`, `-Infinity`, or `NaN`.

isFinite(10); // true
isFinite(Infinity); // false

Is 10 / 2 a finite number?

?

isNaN()

Checks if a value is `NaN` (Not-a-Number). It's the only reliable way to check for `NaN` because `NaN === NaN` is `false`.

isNaN(NaN); // true
isNaN('hello' * 5); // true

Is 'apple' * 3 a number?

?

parseFloat()

Parses a string and returns a floating-point number. It stops parsing when it encounters a character that is not a valid part of the number.

parseFloat("10.50px"); // 10.5
parseFloat("  123.45  go"); // 123.45
= ?

parseInt()

Parses a string and returns an integer. It stops at the first non-numeric character and can handle different number bases (radix).

parseInt("10.50px"); // 10
parseInt("11", 2); // 3 (binary to decimal)
= ?

URI Encoding/Decoding

Functions for encoding and decoding Uniform Resource Identifiers (URIs). They convert characters to and from a special format that is safe for URLs.

encodeURIComponent("https://example.com/page?q=Hello World");
// "https%3A%2F%2Fexample.com%2Fpage%3Fq%3DHello%20World"

Deprecated Functions

These functions are no longer recommended for use due to security and standardization issues. It's best to use `encodeURIComponent` and `decodeURIComponent` instead.

escape("Hello World!"); // "Hello%20World%21"
unescape("Hello%20World%21"); // "Hello World!"

These functions are **deprecated** and should not be used in new code. They are here for historical context.

⚠️ **Warning:** Avoid using `escape()` and `unescape()`. Use `encodeURIComponent()` and `decodeURIComponent()` instead.